#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=1000005;
int n,m; 
int a[N];
bool flag;
vector<pii>ans;
void add(int x,int y)
{
	if (flag) ans.pb(mkp(y,x));
	else ans.pb(mkp(x,y));
}
void print()
{
	cout << SZ(ans) << endl;
	for (pii i:ans) cout << i.fi << " " << i.se << endl;
	exit(0);
}
void solve(int n,int m)
{
	if (n==m)
	{
		rep(i,1,n) add(1,i);
		rep(i,2,n-1) add(n,i);
		return;
	}
	if (n>m)
	{
		flag^=1;
		solve(m,n);
		return;
	}
	if (n%2==1&&m==2*n)
	{
		rep(i,1,n) add(i,1),add(i,m);
		int z=(n-1)/2;
		rep(i,n-z+1,n+z) add((n+1)/2,i);
		return;
	}
	rep(i,1,n) add(i,m);
	solve(n,m-n);
}

int main()
{
	freopen("bishop.in","r",stdin);
	freopen("bishop.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	if (n==1&&m==1)
	{
		add(1,1);
		print();
	}
	solve(n,m);
	print();
	return 0;
}
